﻿using System;

using ApplicationLibrary;
using ApplicationLibrary.SqlConnector;

namespace Clothes.Items.ModuleData
{
    internal class RegisterModule : ApplicationLibrary.SqlConnector.RegisterModule
    {
        public override string Application()
        {
            return "CLOT";
        }

        public override string Module()
        {
            return "ITEM";
        }

        public override int CurrentVersion()
        {
            return 1;
        }

        public override Version DllVersion
        {
            get
            {
                return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
            }
        }

        public override void RegisterCountersAndCodes()
        {
            GlobalInfo.AddCounter(Counters.Categories.Int(), Properties.Resources.CN_Categories);
            GlobalInfo.AddCounter(Counters.Items.Int(), Properties.Resources.CN_Items);

            GlobalInfo.AddCodeType(Codes.ITEMS.ToString(), Properties.Resources.CD_Items);
        }

        public override void AddScrounger(ApplicationLibrary.DBManager.iScrounger frm, NameSpace nameSpace)
        {
            if (nameSpace.ApplicationPath == "Clothes.Masters.Forms.Masters")
                frm.ScroungerList.Add(new Clothes.Items.Scrounger.ItemsScrounger(frm));
        }

        public override ApplicationLibrary.Preferences.PreferencePanel[] RegisterPreferences()
        {
            //return new ApplicationLibrary.Preferences.PreferencePanel[]
            //{
            //    new AccountingPreferencePanel()
            //};
            return null;
        }

        protected override bool CreateDBTables()
        {
            SqlCreateTable newTable = new SqlCreateTable(SqlABConnection);
            #region CL_Categories
            if (SearchTable(CL_Categories.Name))
            {
                newTable.NewTable(CL_Categories.Name);

                newTable.AddColumn(CL_Categories.CodeFather);
                newTable.AddColumn(CL_Categories.Code);
                newTable.AddColumn(CL_Categories.Description);

                newTable.AddPrimaryKey(CL_Categories.Code);
                //newTable.AddSecondaryKey("Father", CL_Categories.CodeFather, CL_Categories.Code);

                newTable.Create();
            }
            #endregion

            #region CL_Items
            if (SearchTable(CL_Items.Name))
            {
                newTable.NewTable(CL_Items.Name);

                newTable.AddColumn(CL_Items.ID);
                newTable.AddColumn(CL_Items.Description);
                newTable.AddColumn(CL_Items.Designer);
                newTable.AddColumn(CL_Items.Size);
                newTable.AddColumn(CL_Items.Color);
                newTable.AddColumn(CL_Items.Pattern);
                newTable.AddColumn(CL_Items.Material);
                newTable.AddColumn(CL_Items.Category);
                newTable.AddColumn(CL_Items.Customer);
                newTable.AddColumn(CL_Items.ReceivingData);
                newTable.AddColumn(CL_Items.Price);
                newTable.AddColumn(CL_Items.CanLowPrice);
                newTable.AddColumn(CL_Items.LowPricePerc);
                newTable.AddColumn(CL_Items.QuotePrice);
                newTable.AddColumn(CL_Items.Status);
                newTable.AddColumn(CL_Items.SoldDate);
                newTable.AddColumn(CL_Items.PriceSale);
                newTable.AddColumn(CL_Items.BillOfLading);
                newTable.AddColumn(CL_Items.ReturnToCustomer);
                newTable.AddColumn(CL_Items.Invoice);
                newTable.AddColumn(CL_Items.BillOfLadingNo);
                newTable.AddColumn(CL_Items.ReturnToCustomerNo);
                newTable.AddColumn(CL_Items.InvoiceNo);
                newTable.AddColumn(CL_Items.Extended);
                newTable.AddColumn(CL_Items.ExtendedDays);
                newTable.AddColumn(CL_Items.DeadLineDate);
                newTable.AddColumn(CL_Items.Printed);

                newTable.AddPrimaryKey(CL_Items.ID);
                newTable.Create();
            }
            #endregion

            return true;
        }

        protected override bool UpdateDBTables()
        {
            //if (dbVersion < 2)
            //{
            //    SqlCreateTable alterMaster = new SqlCreateTable(SqlABConnection);

            //    if (!SearchColumn(FG_Masters.Email))
            //    {
            //        alterMaster.AlterTable(FG_Masters.Name);
            //        alterMaster.AddColumn(FG_Masters.Email);
            //        alterMaster.Alter();
            //    }
            //}

            return true;
        }
    }
}
